//
//  ViewController.m
//  Demo
//
//  Created by 郭健 on 2020/8/28.
//  Copyright © 2020 Seacity. All rights reserved.
//

#define WGSCREEN [UIScreen mainScreen].bounds.size
#define WGWIDTH [UIScreen mainScreen].bounds.size.width
#define WGHEIGHT [UIScreen mainScreen].bounds.size.height
#define WGNAVHEIGHT (WGHEIGHT==812?88:64) //顶部导航栏高度

#import "ViewController.h"

#import "WGModel.h"
@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataArr;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setBaseView];
    [self loadData];
}


- (void)setBaseView{
    self.title = @"ViewController";
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
}


- (void)loadData{
    self.dataArr = @[@"不传值", @"只有属性传值", @"只有initWith传值", @"既有property又有initWith方式传值"];
}

#pragma mark -<UITableViewDelegate, UITableViewDataSource>
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class]) forIndexPath:indexPath];
    
    cell.textLabel.text = [self.dataArr objectAtIndex:indexPath.row];
    return cell;
}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    switch (indexPath.row) {
        case 0:{
            [[SC_ControllerPush SC_ControllerPushShare] pushFromController:self toCon:@"DetailViewController" projName:nil];
            break;
        }case 1:{
            //                方式二：只有属性传值,存储属性的字典,属性的名字作为key-------------------------
            NSDictionary *propertyDic = @{@"name":@"Seacity"};
            //外层用@"property"作为key包装,为了识别哪些值需要属性传值
            NSDictionary *paramDic = @{
                SCProperty:propertyDic
            };
            [[SC_ControllerPush SC_ControllerPushShare] pushFromController:self toCon:@"DetailViewController" paramType:SCPushProperty param:paramDic projName:nil];
            break;
        }case 2:{
            //    方式三：只有init方式传值-------------------------
            WGModel *model = [[WGModel alloc] init];
            model.name = @"小明";
            model.age = 18;
            //key是重写init的函数名字,值按照顺序放在一个数组中
            NSArray *valueArr = @[
                @{
                    @"height":@(179),
                    @"address":@"人民路"
                },
                model,
                @[@"数组元素",@"18.123"]
            ];
            
            NSDictionary *initDic = @{
                @"initWithDic:model:array:":valueArr
            };
            
            NSDictionary *paramDic = @{
                SCInitWith:initDic
            };
            [[SC_ControllerPush SC_ControllerPushShare] pushFromController:self toCon:@"SecondDetailViewController" paramType:SCPushInit param:paramDic projName:nil];
            break;
        }case 3:{
            //    方式四：既有property又有initWith方式传值 -------------------------
            NSDictionary *paramDic = @{
                SCInitWith:@{
                        @"initWithDic:":@[
                                @{
                                    @"height":@(179.12),
                                    @"address":@"人民路",
                                    @"hasGirFirend":@(NO)
                                }
                        ]
                },
                SCProperty:@{
                        @"school":@"太和一中",
                        @"age":@(18),
                        @"isMale":@(YES)
                }
            };
            [[SC_ControllerPush SC_ControllerPushShare] pushFromController:self toCon:@"SC_OtherViewController" paramType:SCPushOther param:paramDic projName:nil];
            break;
        }
        default:
            break;
    }
}


#pragma mark -懒加载
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WGWIDTH, WGHEIGHT) style:UITableViewStylePlain];
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
    }
    return _tableView;
}

-(NSArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [[NSArray alloc] init];
    }
    return _dataArr;
}



@end
